package com.oa.modules.approvalsec1.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.oa.modules.approvalsec1.entity.NewsNoticeEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 *
 *
 * @author jiangwei
 * @email 785297226@qq.com
 * @date 2021-03-26 10:09:17
 */
@Mapper
public interface NewsNoticeDao extends BaseMapper<NewsNoticeEntity> {


    /**
     * 查询总条数
     *
     * @author jiangwei
     * @email 785297226@qq.com
     * @date 2021-03-26 10:09:17
     * @Description 查询分页数据
     */
    @Select("<script>SELECT COUNT( 1 ) FROM (" +
            "select t1.* from news_notice t1  " +
            "where 1=1 " +
            "<if test = 'params != null '> "+
            "and t1.`STATUS` = #{params.status} " +
            ") </if> TOTAL</script>")
    long findPage(@Param("params") Map<String, Object> params);

    /**
     * 查询分页数据
     *
     * @author jiangwei
     * @email 785297226@qq.com
     * @date 2021-03-26 10:09:17
     * @Description 查询分页数据
     */
    @Select("<script>select t1.* from news_notice t1 " +
            "where 1=1 " +
            "and t1.`STATUS` = #{params.status} " +
            "ORDER BY t1.CREATE_DATE desc</script>")
    List<NewsNoticeEntity> findRecords(IPage<NewsNoticeEntity> page, @Param("params") Map<String, Object> params);

    /**
     * 查询每个用户帮办和立即办的数据
     *
     * @author jiangwei
     * @email 785297226@qq.com
     * @date 2021-03-26 10:09:17
     * @Description 查询每个用户帮办和立即办的数据
     */
    @Select("<script>select t1.PUSH_USER_ID, " +
            "sum(case when t1.READ_STATUS = '0' and t1.MATTER_TYPE = '0' then 1 else 0 end) as bHandle, " +   //帮办
            "sum(case when t1.READ_STATUS = '0' and t1.MATTER_TYPE = '1' then 1 else 0 end) as lHandle, " +   //立即办
            "sum(case when t1.READ_STATUS = '0' and t1.MATTER_TYPE = '2' then 1 else 0 end) as dHandle " +    //督办
            "from news_notice t1 GROUP BY t1.PUSH_USER_ID</script>")
    List<NewsNoticeEntity> queryNotices();
}
